﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dillema.example_to_agents;
using System.IO;


namespace Dillema
{
    interface Agent
    {
        bool Response(bool last_action);//אני מניח שהסטודנטים ישמרו את ההסטוריה אם הם ירצו במהלך הראשון
        bool Reset();//הסוכן יתכונן לטורניר חדש וישלח את המהלך הראשון שלו
        //false = בגידה
    }

    class Program
    {
        static void Main(string[] args)
        {
            //כאן צריך להכניס את הרשימה של הסוכנים
            Agent[] agents ={
                           new TheKiller(),
                           //new David()...
                           new Pure_bad(),
                           //new Pure_good(),
                           //new Tit_for_tat(),
                           //new PasswordBaseStategy1(),
                           //new PasswordBaseStategy2()
                       };
            int[,] pay_off_matrix =
            {   {-1,-4},
                {0,-3}    
            };
            runTurnir(agents, 1000/*כמות התורות בקרב*/, 1/*כמות הטורנירים*/, pay_off_matrix);
        }

        private static void runTurnir(Agent[] agents, int number_of_turns, int number_of_wars, int[,] pay_off_matrix)
        {
            int[] result = new int[agents.Length];
            Random RND = new Random();
            string[] set_file=new string[1500];

            for (int i = number_of_wars; i > 0; i--)
                foreach (Agent agentA in agents)
                {
                    int a_score = 0;
                    foreach (Agent agentB in agents)
                    {
                        if (agentA == agentB)
                            continue;
                        bool a_last_action = agentA.Reset();
                        bool b_last_action = agentB.Reset();
                        set_file[0] = "****** turn = " + 0 + " *****\n" + "  a:" + a_last_action + ", b:" + b_last_action;
                        bool a_current_action;
                        bool b_current_action;


                        for (int j = number_of_turns; j > 0; j--)
                        {
                            a_current_action = agentA.Response((RND.Next(0, 20) == 0) ? !b_last_action : b_last_action);
                            b_current_action = agentB.Response((RND.Next(0, 20) == 0) ? !a_last_action : a_last_action);
                            set_file[number_of_turns - j + 1] = "****** turn = " + (number_of_turns - j + 1) + " *****\n" + "  a:" + a_current_action + ", b:" + b_current_action;

                            a_score += pay_off_matrix[a_last_action ? 0 : 1, b_last_action ? 0 : 1];

                            a_last_action = a_current_action;
                            b_last_action = b_current_action;
                        }
 
 
                    }
                    Console.Write(agentA.GetType().Name + " score is:" + a_score + "\n");
                    File.WriteAllLines("history.txt", set_file);
                }
            Console.Read();
        }

    }
}
